package com.forester.foresterplatform.system.service;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.forester.foresterplatform.common.utils.MyBatisPlusUtils;
import com.forester.foresterplatform.system.entity.BaseEntity;

import java.util.List;

public interface BaseService <T extends BaseEntity> extends IService<T> {
    default Page<T> page(Integer page, Integer size, String sort, T condition){
        List<OrderItem> orderItems = MyBatisPlusUtils.parseSort(sort);
        Page<T> p = new Page<>(page, size);
        p.setOrders(orderItems);
        getBaseMapper().selectPage(p, buildPageQueryWrapper(condition));
        return p;
    }

    default Wrapper<T> buildPageQueryWrapper(T condition){
        return null;
    }
}
